CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)

# The name of the project.
PROJECT(VisGraB)

# Used to resolve absolute path names
SET(ROOT ${CMAKE_CURRENT_SOURCE_DIR})

set(CMAKE_VERBOSE_MAKEFILE false)

# Now set the RW/RWS root (edit this if necessary)
SET(RobWork_DIR "${ROOT}/../RobWorkTrunk/RobWork/cmake")
SET(RobWorkStudio_DIR "${ROOT}/../RobWorkTrunk/RobWorkStudio/cmake")
SET(RobWorkSim_DIR "${ROOT}/../RobWorkTrunk/RobWorkSim/cmake")

# We use the settings that robwork studio uses
IF( NOT CMAKE_BUILD_TYPE ) 
	set(CMAKE_BUILD_TYPE Debug)
ENDIF()

SET(CMAKE_MODULE_PATH ${ROOT} ${CMAKE_MODULE_PATH})

# lets first check that the user added valid RobWork paths, this should be handled automaitica
#FIND_FILE(ROBWORKFOUND "FindRobWork.cmake" "${RobWork_DIR}")
#FIND_FILE(ROBWORKSTUDIOFOUND "FindRobWorkStudio.cmake" "${RWS_ROOT}/build")
#FIND_FILE(ROBWORKSIMFOUND "FindRobWorkSim.cmake" "${RWSIM_ROOT}/build")
#IF( NOT ROBWORKFOUND ) 
# MESSAGE(FATAL_ERROR "Please specify a valid RobWork path!") 
#ENDIF()
#IF( NOT ROBWORKSTUDIOFOUND ) 
# MESSAGE(FATAL_ERROR "Please specify a valid RobWorkStudio path!") 
#ENDIF()
#IF( NOT ROBWORKSIMFOUND ) 
# MESSAGE(FATAL_ERROR "Please specify a valid RobWorkSim path!") 
#ENDIF()



#Include RobWorkSim settings
#SET(CMAKE_MODULE_PATH ${RW_ROOT}/build ${CMAKE_MODULE_PATH})
#SET(CMAKE_MODULE_PATH ${RWSIM_ROOT}/build ${CMAKE_MODULE_PATH})
FIND_PACKAGE(RobWork REQUIRED)
FIND_PACKAGE(RobWorkStudio REQUIRED)
FIND_PACKAGE(RobWorkSim REQUIRED)
INCLUDE_DIRECTORIES( ${ROBWORK_INCLUDE_DIRS} ${ROBWORKSTUDIO_INCLUDE_DIRS} ${ROBWORKSIM_INCLUDE_DIRS})
LINK_DIRECTORIES( ${ROBWORK_LIBRARY_DIRS} ${ROBWORKSTUDIO_LIBRARY_DIRS} ${ROBWORKSIM_LIBRARY_DIRS})

# Set the output dir for generated libraries and binaries
IF(MSVC)
	SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${ROOT}/bin" CACHE PATH "Runtime directory" FORCE)
	SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${ROOT}/libs" CACHE PATH "Library directory" FORCE)
	SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${ROOT}/libs" CACHE PATH "Archive directory" FORCE)
ELSE()
	SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${ROOT}/bin/${CMAKE_BUILD_TYPE}" CACHE PATH "Runtime directory" FORCE)
	SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${ROOT}/libs/${CMAKE_BUILD_TYPE}" CACHE PATH "Library directory" FORCE)
	SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${ROOT}/libs/${CMAKE_BUILD_TYPE}" CACHE PATH "Archive directory" FORCE)
ENDIF()

# copy the invkin file for inverse kinematics generation of SDH
CONFIGURE_FILE(bin/SDHDeviceInvKin.wc.xml ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/SDHDeviceInvKin.wc.xml)
#  OpenCV_FOUND
#  OpenCV_INCLUDE_DIR
#  OpenCV_LIBRARIES
#  OpenCV_LINK_DIRECTORIES


# Add OpenCV and boost-bindings directories
FIND_PACKAGE(OpenCV REQUIRED NO_MODULE)

MESSAGE(STATUS "VisGraB: Found OpenCV version ${OpenCV_VERSION}")

set(CMAKE_CXX_FLAGS "-g -Wall -Wno-deprecated ")

INCLUDE_DIRECTORIES( 
  ${ROOT}/src
  ${OpenCV_INCLUDE_DIRS}
  boost-numeric-bindings
)
#LINK_DIRECTORIES(  )

set(cpp_sources_prepexp
  src/Database.cpp
  src/planeFit/TablePlane.cpp
  src/planeFit/PointCloudFilterTable.cpp
  src/STLWriter.cpp
  src/MyGraspGenerator.cpp
  src/prepareExperiments.cpp
)
set(cpp_sources_readres
  src/readResults.cpp
)

add_executable(prepareExperiments WIN32 ${cpp_sources_prepexp})
target_link_libraries(prepareExperiments
  ${ROBWORK_LIBRARIES}
  ${OpenCV_LIBS} 
  boost_filesystem boost_system lapack rw
)


add_executable(readResults WIN32 ${cpp_sources_readres})
target_link_libraries(readResults
  boost_filesystem boost_system
)

set_property(TARGET prepareExperiments readResults APPEND PROPERTY 
  COMPILE_DEFINITIONS
  OpenCV_VERSION_MAJOR=${OpenCV_VERSION_MAJOR}
  OpenCV_VERSION_MINOR=${OpenCV_VERSION_MINOR}
)


add_executable(VisGraB src/VisGraB.cpp src/VisGraBGraspTask.cpp src/VisGraBBenchmark.cpp src/SDHInvKinSolver.cpp)
target_link_libraries(VisGraB rwsim ${ROBWORK_LIBRARIES} ${ROBWORKSIM_LIBRARIES})


add_executable(RobWorkStudioExt src/main.cpp)
target_link_libraries(RobWorkStudioExt 
     rwsim 
     RWSimPlugin
     SimTaskPlugin
     SimTaskVisPlugin
     ${ROBWORKSIM_LIBRARIES} 
     ${ROBWORKSTUDIO_LIBRARIES} 
     ${ROBWORK_LIBRARIES})


